# -*- coding: utf-8 -*-

# Create your views here.
from data.models import Data
from django.http import HttpResponseRedirect
from django.shortcuts import render_to_response
from django.template import RequestContext
from django.views.decorators.csrf import ensure_csrf_cookie
from google.appengine.api.datastore_types import GeoPt
import random

@ensure_csrf_cookie
def autoProcess(request):
    if request.method == 'GET':
        objects = Data.gql('ORDER BY totalPrice DESC')
        return render_to_response('template_AutoProcess.html',
                                  {'datas':objects},
                                  context_instance=RequestContext(request)
                                  )
    if request.method == 'POST':
        lat = random.random() * 100
        lng = random.random() * 100
        
        data = Data(totalPrice = 100000,
                    district = '中山區',
                    target = '商',
                    pt = GeoPt(lat, lng)
                    )
        data.put();
        return HttpResponseRedirect('/data/auto/')
        
